<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<title>阳光图书馆_馆藏查询</title>
	<style>
		body {
			background-image: url(image/home_bg.jpg);
			background-repeat: no-repeat;
		}
	</style>
	<link rel="stylesheet" href="css/direction.css">
	<link rel="stylesheet" href="css/ns_search.css">

	<!-- 新 Bootstrap4 核心 CSS 文件 -->
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
	<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	<!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
	<script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
	<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
	<script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>

	<script src="js/u_r_s.js"></script>

</head>

<body>

	<nav class="direct_bar">
		<div class="logo"> <a href="index.html"><img src="image/sunny.png" style="width: 235px; height: 45px" class="img_logo"></a> </div>
		<div class="page_links" style="height:50px">
			<ul class="nav justify-content-center">
				<li class="nav-item"><a href="index.html" class="nav-link">首&nbsp;&nbsp;页</a>
				</li>
				<li class="nav-item"><a href="netsource.php" class="nav-link">馆藏查询</a>
				</li>
				<li class="nav-item"><a href="serveInstruction_1.html" class="nav-link">服务指南</a>
				</li>
				<li class="nav-item"><a href="user.html" class="nav-link">个人中心</a>
				</li>
			</ul>
		</div>
		<form class="search" action="netsource.php" method="post" id="myform">
			<input type="text" class="form-control" name="bookname2" id="ser_input" placeholder="搜索书名、类型、序列号"/>
			<input type="image" src="image/search.png" style="width: 25px" class="img_ser" onClick="document.getElementById('myform').submit()" name="submit">
		</form>
		<div class="identity">
			<ul class="nav justify-content-center">
				<li class="nav-item"><img src="image/user.png" style="width: 50px ;" class="img_user"/>
				</li>
				<li class="nav-item"><a href="login.html" class="nav-link">登录</a>
				</li>
				<li class="nav-item"><a href="register.php" class="nav-link">注册</a>
				</li>
			</ul>
		</div>
	</nav>
	<br>
	<br>

	<div class="container my-container" style="background-color:rgba(253,253,253,0.72);border-radius:20px;padding:50px">


		<form action="" class="form-group" method="post">
			<h4>根据书号查询</h4>
			<label for="">书号:</label>
			<input type="text" class="form-control" name="booknum" placeholder="请输入书号 如 1，2，3"><br>
			<center><button type="submit" class="btn btn-info" name="submit">检索</button>
			</center>
			<hr>
			<h4>根据书名查询</h4>
			<label for="">书名:</label>
			<input type="text" class="form-control" name="bookname" placeholder="请输入书名 如 数学"><br>
			<center><button type="submit" class="btn btn-info" name="submit">检索</button>
			</center>
		</form>
	</div><br>


	<!--   具体的php连接数据库效果请转至  http://www.jimmyking.cn:8080/ 查看  -->

	<div class="modal fade" id="ipt_wrong">
		<div class="modal-dialog">
			<div class="modal-content">

				<div class="modal-header">
					<h4 class="modal-title">警告</h4>
					<button type="button" class="close" data-dismiss="modal">&times;</button>
				</div>


				<div class="modal-body">
					输入错误
				</div>


				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
				</div>

			</div>
		</div>
	</div>
	<?php
	if ( isset( $_POST[ "submit" ] ) || !empty( $_POST[ "bookname2" ] ) ) {
		$selsql = "";
		include( "connect.php" );
		$bookname = "";
		$booknum = "";
		if ( !empty( $_POST[ "booknum" ] ) ) {
			$booknum = $_POST[ "booknum" ];

			if ( preg_match( "/^[0-9]+$/", $booknum ) == true ) {
				$selsql = "select * from book where id =$booknum;";
			} else {
				?>
	<script>
		$( '#ipt_wrong' ).modal( 'show' );
	</script>
	<?php

	}
	} else if ( !empty( $_POST[ "bookname" ] ) ) {
		$bookname = $_POST[ "bookname" ];
		$selsql = "select * from book where name like \"%$bookname%\";";
	} else if ( !empty( $_POST[ "bookname2" ] ) ) {
		$bookname = $_POST[ "bookname2" ];
		$selsql = "select * from book where name like \"%$bookname%\";";
	}
	$resultsql = $conn->query( $selsql );
	?>

	<div class="modal fade" id="ans">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title">查询结果</h4>
					<button type="button" class="close" data-dismiss="modal">&times;</button>
				</div>
				<?php
				if ( $resultsql->num_rows > 0 ) {
					?>
				<div class="modal-body">
					<table class="table table-hover">
						<thead>
							<tr>
								<th>书号</th>
								<th>书名</th>
								<th>馆藏地</th>
								<th>借阅状态</th>
							</tr>
						</thead>
						<tbody>
							<?php
							while ( $row = $resultsql->fetch_assoc() ) {
								echo "<tr><td>" . $row[ "id" ] . "</td><td>" . $row[ "name" ] . "</td>";
								?>
							<td>第一借阅室</td>
							<td>可借</td>
							</tr>
							<?php
							}
							?>
						</tbody>
					</table>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
				</div>
				<?php
				} else {
					?>
				<div class="modal-body">
					没有相关结果
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
				</div>
				<?php

				}
				$conn->close();
				}
				?>
			</div>
		</div>
	</div>
	<script>
		$( '#ans' ).modal( 'show' );
	</script>
	<br>
	<br>
</body>

</html>